new Vue({
    el: '#app',
    mixins: [Save],//组件配置文件，路径/utils/components.js
    data() {
        return {
            dataForm: {},
            childDataForm: [{
                article_specifications:[]
            }],
            childDataForm1: [{}],
            article_info: [],
            merchant: [],
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.init(); //初始化文件
         * 2.this.getData(); //仅修改时执行，根据BOM配置属性查询
         */
        this.init();
        this.getList();
    },
    computed: {
        merchant_() {
            return function (index) {
                const { merchant, childDataForm1 } = this;
                return merchant.filter(i => i.Merchant_SerialNumber == childDataForm1[index].Merchant_SerialNumber || !childDataForm1.filter(item => item.Row_Status != '1').some(x => i.Merchant_SerialNumber == x.Merchant_SerialNumber));
            }
        }
    },
    methods: {
        handleDate(val, str) { //处理空指针
            if (val == null) {
                this.dataForm[str] = '';
            }
        },
        getList() {
            httpRequest({
                url: '/generalBusiness/queryMultiTableByCondition',
                data: {
                    Data: JSON.stringify([{
                        tableName: 'article_info',
                        Condition: utf8ToBase64(`Row_Status='0'`),
                    }, {
                        tableName: 'merchant',
                        Condition: utf8ToBase64(`Row_Status<>'1'`),
                    }])
                },
            }).then(data => {
                const { article_info, merchant } = data;
                this.article_info = article_info;
                this.merchant = merchant;
            }).catch(xhr => {
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            })
        },
        handleAdd1(formName) {//添加数据
            try {
                if (this.action === 'Add') {//添加
                    this[formName].push({
                        article_specifications:[]
                    });
                }
            } catch (error) {
                console.error(error);
                this.$message.error("系统错误，请联系开发者!");
            }
        },
        handleChange(val, item) {
            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'article_specifications',
                    Condition: `Row_Status='0' AND Article_SerialNumber='${val}'`
                },
                type: 'GET'
            }).then(data => {
                item.article_specifications = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })
        },
        handlePrice(val, item) {
            let obj = item.article_specifications.filter(i => i.Specifications_SerialNumber == val)[0];
            if (obj) {
                item.Unit_Price = obj.Unit_Price
            } else {
                item.Unit_Price = '';
            }
        }
    }
})